package com.itheima.test03;

import com.itheima.bean.Crouse;
import com.itheima.bean.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class TestManyToMany {
    @Test
    public void selectAllStuToCrouse() throws Exception{
        InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        StuToCrouseMapper stuToCrouseMapper = sqlSession.getMapper(StuToCrouseMapper.class);
        List<Student> students = stuToCrouseMapper.selectAll();
        for (Student student : students) {
            System.out.println(student);
        }
        sqlSession.close();
        is.close();
    }

    @Test
    public void selectAllCrouseToStu()throws Exception{
        InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        CrouseToStuMapper crouseToStuMapper = sqlSession.getMapper(CrouseToStuMapper.class);
        List<Crouse> crouses = crouseToStuMapper.selectAll();
        for (Crouse crouse : crouses) {
            System.out.println(crouse);
        }
        sqlSession.close();
        is.close();
    }
}
